﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace webapp4U.UI
{
    public partial class FAQAdd : System.Web.UI.Page
    {
        int FAQID = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Action"] == "Edit")
            {
                FAQID = Globals.GetIntFromQueryString("FAQID");
                btSave.Text = ResourceManager.GetString("Update");
                if (!IsPostBack)
                    Load_FAQByID();
            }
        }


        private void Load_FAQByID()
        {
            webapp4U.BOL.FAQ obj = webapp4U.BOL.FAQ.GetFAQByID(FAQID);
            dlLanguages.SelectedValue = obj.LanguageCode.ToString();
            txtQuestion.Text = obj.Questions;
            txtAnswer.Text = obj.Answer;
            
        }


        protected void btSave_Click(object sender, EventArgs e)
        {
            webapp4U.BOL.FAQ obj = new webapp4U.BOL.FAQ();
            obj.AddedBy = Globals.CurrentUserName;
            obj.QuestionsDate = DateTime.Now;
            obj.AnswerDate = DateTime.Now;
            obj.FAQID = this.FAQID;
            obj.Questions = txtQuestion.Text;
            obj.Answer = txtAnswer.Text;
            obj.LanguageCode = dlLanguages.SelectedItem.Value;
            obj.Answered = true;
            obj.Display = true;            


            if (Globals.GetStringFromQueryString("Action") == "Edit")
            {
                webapp4U.BOL.FAQ.Update(obj);
            }
            else
            {
                webapp4U.BOL.FAQ.Insert(obj);                
               
            }
            PanelMsg.Visible = true;
            lblMsg.Text = ResourceManager.GetString("ModifiedSuccessfully");

            Response.Redirect(Globals.ApplicationPath + "WebMaster/FAQ/");
        }       
    }
}